using System;
using System.Collections.Generic;
using System.Drawing;

namespace Clandestine.Engines.Field.Collision
{
	public class Edge
	{
		public readonly Point StartPoint;
		public readonly Point EndPoint;
		
		public Edge(Point p1, Point p2)
		{
			this.StartPoint = p1;
			this.EndPoint = p2;
			this.update();
		}
		
		private void update()
		{
			// Find line equation. y=mx+c
			int dx = EndPoint.X - StartPoint.X;
			if (dx == 0)
				dx = 1; // hey, w/e.
			m = (EndPoint.Y - StartPoint.Y) / ((double) dx); // m=dY/dX
			// y = mx+c  => c=y-mx
			c = StartPoint.Y - (m * StartPoint.X);
			
			lx = (StartPoint.X < EndPoint.X ? StartPoint.X : EndPoint.X);
			gx = (StartPoint.X > EndPoint.X ? StartPoint.X : EndPoint.X);
		}
		
		internal double m;
		internal double c;
		internal double lx;
		internal double gx;
	}
}

